//
//  JCNSDictionaryToNSStringTransform.m
//  JCTest
//
//  Created by master on 16/3/4.
//  Copyright © 2016年 AdMaster. All rights reserved.
//

#import "JCNSDictionaryToNSStringTransform.h"

@implementation JCNSDictionaryToNSStringTransform

+ (Class)transformedValueClass {
    return [NSDictionary class];
}

+ (BOOL)allowsReverseTransformation {
    return YES;
}

- (id)transformedValue:(id)value {
    NSData *data = [NSJSONSerialization dataWithJSONObject:value options:NSJSONWritingPrettyPrinted error:nil];
    return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
}

- (id)reverseTransformedValue:(id)value {
    return [NSJSONSerialization JSONObjectWithData:[value dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableLeaves error:nil];
}

@end
